const app = getApp()
class EasyHttp {
  post(url, json) {
    return new Promise((resolve, reject) => {
      wx.request({
        url,
        data: json,
        method: 'POST',
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        success(res) {

          if (res.data.status == -110) {
            wx.hideLoading();
            wx.showModal({
              showCancel: false,
              content: `登录已过期，请重新登录`,
              success(res) {
                if (res.confirm) {
                  wx.clearStorage('userInfo')
                  app.globalData.userInfo = null;
                  wx.redirectTo({
                    url: '/pages/login/login',
                  })
                }
              }
            })
            return
          } else if (res.data.status == -120) {
            wx.hideLoading();
            wx.showModal({
              showCancel: false,
              content: res.data.msg,
              success(res) {

              }
            })
          }

          resolve(res)
        },
        fail(err) {
          reject(reject)
        }
      })
    })
  }
}
module.exports = {
  EasyHttp: new EasyHttp
}